home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / AREAS.MOD < prev    next >
Text File  |  1989-01-18  |  3KB  |  97 lines

  1. (* This program is actually a very silly program with little or    *)
  2. (* no utilitarian value.  It is valuable as an illustration of a   *)
  3. (* method of implementing a menu for selection purposes.  Notice   *)
  4. (* when you run it, that the response to your input is immediate   *)
  5. (* No "return" is required.                                        *)
  6.  
  7. MODULE Areas;
  8.  
  9. FROM InOut IMPORT Read, WriteString, Write, WriteLn;
  10. FROM RealInOut IMPORT WriteReal, ReadReal;
  11.  
  12. VAR InChar, CapInChar : CHAR;
  13.  
  14. (* ************************************************** AreaOfSquare *)
  15. PROCEDURE AreaOfSquare;
  16. VAR Length, Area : REAL;
  17. BEGIN
  18.    WriteString("Square    Enter length of a side ");
  19.    ReadReal(Length);
  20.    Area := Length * Length;
  21.    WriteLn;
  22.    WriteString("The area is ");
  23.    WriteReal(Area,15);
  24.    WriteLn;
  25. END AreaOfSquare;
  26.  
  27. (* *********************************************** AreaOfRectangle *)
  28. PROCEDURE AreaOfRectangle;
  29. VAR Width, Height, Area : REAL;
  30. BEGIN
  31.    WriteString("Rectangle    Enter Width ");
  32.    ReadReal(Width);
  33.    WriteLn;
  34.    WriteString("Enter Height ");
  35.    ReadReal(Height);
  36.    Area := Width * Height;
  37.    WriteString("      The area is ");
  38.    WriteReal(Area,15);
  39.    WriteLn;
  40. END AreaOfRectangle;
  41.  
  42. (* ************************************************ AreaOfTriangle *)
  43. PROCEDURE AreaOfTriangle;
  44. VAR Base, Height, Area : REAL;
  45. BEGIN
  46.    WriteString("Triangle    Enter base ");
  47.    ReadReal(Base);
  48.    WriteLn;
  49.    WriteString("Enter height ");
  50.    ReadReal(Height);
  51.    Area := 0.5 * Base * Height;
  52.    WriteString("      The area is ");
  53.    WriteReal(Area,15);
  54.    WriteLn;
  55. END AreaOfTriangle;
  56.  
  57. (* ************************************************** AreaOfCIrcle *)
  58. PROCEDURE AreaOfCircle;
  59. VAR Radius, Area : REAL;
  60. BEGIN
  61.    WriteString("Circle      Enter Radius ");
  62.    ReadReal(Radius);
  63.    WriteLn;
  64.    Area := 3.141592 * Radius * Radius;
  65.    WriteString("The area is ");
  66.    WriteReal(Area,15);
  67.    WriteLn;
  68. END AreaOfCircle;
  69.  
  70. (* ************************************************** Main Program *)
  71. BEGIN
  72.    REPEAT
  73.       WriteLn;
  74.       WriteString("You only need to input the first letter ");
  75.       WriteString("of the selection.");
  76.       WriteLn;
  77.       WriteString("Select shape; Square Rectangle Triangle ");
  78.       WriteString("Circle Quit");
  79.       WriteLn;
  80.       WriteString("Requested shape is ");
  81.       Read(InChar);
  82.       CapInChar := CAP(InChar);           (* Get capital of letter *)
  83.       CASE CapInChar OF
  84.         'S' : AreaOfSquare; |
  85.         'R' : AreaOfRectangle; |
  86.         'T' : AreaOfTriangle; |
  87.         'C' : AreaOfCircle; |
  88.         'Q' : WriteString("Quit    Return to DOS");
  89.               WriteLn;
  90.       ELSE
  91.          Write(InChar);
  92.          WriteString(" Invalid Character ");
  93.          WriteLn;
  94.       END;
  95.    UNTIL CapInChar = 'Q';
  96. END Areas.
  97.